﻿using System;
using System.Collections.Generic;

using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using System.Data;
using System.Data.Entity;
using System.Data.EntityClient;
using System.Data.Objects;
using System.Data.SqlClient;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;

namespace UCWebpart.Admin
{
    public partial class MeetingroomUserControl : System.Web.UI.UserControl
    {
        UserInfo userInfo;
        int uLevel = 0;
        List<MTR_Admin> AdminInfoList;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["userInfo"] == null)
            {
                Response.Redirect("../Login.aspx", false);
                return;
            }
            userInfo = (UserInfo)Session["userInfo"];
            AdminInfoList = userInfo.AdminInfoList;
            List<string> company = new List<string>();
            foreach (MTR_Admin ma in AdminInfoList)
            {
                uLevel = uLevel > Convert.ToInt32(ma.adminLevel) ? uLevel : Convert.ToInt32(ma.adminLevel);
            }
            string conn = WebConfigurationManager.ConnectionStrings["meetingroomManagementConnectionString"].ConnectionString;
           
            if (uLevel < 2)//普通管理员
            {
                Div1.Attributes.Add("style", "display:none");//隐藏
            }
            if (uLevel == 2)//高级管理员
            {
                if (!this.IsPostBack)
                {
                    mtrCompanyRuc.DataSource = "";
                    string conn1 = WebConfigurationManager.ConnectionStrings["WorkFlowConnectionString"].ConnectionString;
                    string strSQL1 = "select distinct ABBR,id from [WorkFlow].[dbo].[RUC_Organization](nolock) where OrgTypeID=1 and IfDelete=0 and ABBR !='' order by id ";
                    mtrCompanyRuc.DataSource = Worker.GetDataSet(strSQL1, conn1);
                    mtrCompanyRuc.DataTextField = "ABBR";
                    mtrCompanyRuc.DataValueField = "ABBR";
                    mtrCompanyRuc.DataBind();

                    string strSQL = string.Format(@"select distinct [MTR_bas_Admin].VenueType from MTR_bas_Admin with(nolock)
                        where adminName ='{0}'and MTR_bas_Admin.Available='1' and MTR_bas_Admin.adminLevel=2", Session["userName"].ToString());
                    types.DataSource = Worker.GetDataSet(strSQL, conn);
                    types.DataTextField = "VenueType";
                    types.DataValueField = "VenueType";
                    types.DataBind();

                    if (types.Items[0].Text == "会议室")
                    {
                        mtrLongestBookingDay.Text = "4";
                        mtrLongestAdvanceBookingTime.Text = "15";
                    }

                    string sql = string.Format("select distinct [MTR_bas_Admin].[adminName] FROM [VenueBooking].[dbo].[MTR_bas_Admin] where Available = 1 and adminLevel =1 and VenueType = '{0}'", types.SelectedItem.Text);
                    admin.DataSource = Worker.GetDataSet(sql, conn); ;
                    admin.DataTextField = "adminName";
                    admin.DataValueField = "adminName";
                    admin.DataBind();
                    getDeptBind();
                }
            }
            if (uLevel >= 3)
            {
                if (!this.IsPostBack)
                {
                    mtrCompanyRuc.DataSource = "";
                    string conn1 = WebConfigurationManager.ConnectionStrings["WorkFlowConnectionString"].ConnectionString;
                    string strSQL = "select distinct ABBR,id from [WorkFlow].[dbo].[RUC_Organization](nolock) where OrgTypeID=1 and IfDelete=0 and ABBR !='' order by id ";
                    mtrCompanyRuc.DataSource = Worker.GetDataSet(strSQL, conn1);
                    mtrCompanyRuc.DataTextField = "ABBR";
                    mtrCompanyRuc.DataValueField = "ABBR";
                    mtrCompanyRuc.DataBind();
                    string strSQL1 = string.Format(@"SELECT [Type] FROM [VenueBooking].[dbo].[MTR_bas_Type] where available = 1");
                    types.DataSource = Worker.GetDataSet(strSQL1, conn);
                    types.DataTextField = "Type";
                    types.DataValueField = "Type";
                    types.DataBind();
                    if (types.Items[0].Text == "会议室") 
                    {
                        mtrLongestBookingDay.Text = "4";
                        mtrLongestAdvanceBookingTime.Text = "15";
                    }

                    string sql = string.Format("select distinct [MTR_bas_Admin].[adminName] FROM [VenueBooking].[dbo].[MTR_bas_Admin] where Available = 1 and adminLevel =1 and VenueType = '{0}'", types.SelectedItem.Text);
                    admin.DataSource = Worker.GetDataSet(sql, conn); ;
                    admin.DataTextField = "adminName";
                    admin.DataValueField = "adminName";
                    admin.DataBind();
                    getDeptBind();
                }
            }
        }

        protected void getDeptBind()
        {
            string com = mtrCompanyRuc.SelectedItem.Text;
            List<string> dept = new List<string>();
            dept = getDeptByNameComLevel(Session["userName"].ToString(), com, uLevel);
            List_dept.DataSource = dept;
            List_dept.DataBind();
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
     
        protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {

        }


        //选择部门后选择类型
        protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
        {
            DropDownList DeptList = sender as DropDownList;
            GridViewRow gvr = (GridViewRow)DeptList.NamingContainer;
            TextBox dept = gvr.FindControl("TextBox2") as TextBox;
            dept.Text = DeptList.SelectedItem.Text;

            DropDownList company = gvr.FindControl("CompanyList") as DropDownList;
            string com = company.SelectedItem.Text;
            TextBox TBType = gvr.FindControl("TextBox5") as TextBox;
            string cnType = TBType.Text;

            DropDownList venueType = gvr.FindControl("DropDownList4") as DropDownList;
            venueType.DataSource = "";
            venueType.DataTextField = null;
            venueType.DataValueField = null;
            venueType.DataSource = getVenueTypeByNameComLevelDept(Session["userName"].ToString(), com, uLevel);
            venueType.DataBind();

            for (int k = 0; k < venueType.Items.Count; k++)
            {
                if (venueType.Items[k].Text == TBType.Text)
                {
                    venueType.Items[k].Selected = true;
                }
            }
        }

        //选择公司后绑定部门
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList CompanyList = sender as DropDownList;
            GridViewRow gvr = (GridViewRow)CompanyList.NamingContainer;
            TextBox TBcompany = gvr.FindControl("TextBox1") as TextBox;
            TBcompany.Text = CompanyList.SelectedItem.Text;
            TextBox TBDept = gvr.FindControl("TextBox2") as TextBox;
            string cndep = TBDept.Text;

            DropDownList DeptList = gvr.FindControl("DropDownList1") as DropDownList;
            DeptList.DataSource = null;
            DeptList.DataTextField = null;
            DeptList.DataValueField = null;
            DeptList.DataSource = getDeptByNameComLevel(Session["userName"].ToString(), TBcompany.Text, uLevel);
            DeptList.DataBind();
            for (int k = 0; k < DeptList.Items.Count;k++ ) 
            {
                if (DeptList.Items[k].Text == cndep) 
                {
                    DeptList.Items[k].Selected = true;
                }
            }
        }

        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if ((DropDownList)e.Row.FindControl("CompanyList") != null)
            {
                if (uLevel == 3) {
                    //绑定公司
                    DropDownList DDlCompany = (DropDownList)e.Row.FindControl("CompanyList");
                    string conn = WebConfigurationManager.ConnectionStrings["WorkFlowConnectionString"].ConnectionString;
                    string strSQL = "select distinct ABBR,id from [WorkFlow].[dbo].[RUC_Organization](nolock) where OrgTypeID=1 and IfDelete=0 and ABBR !='' order by id ";
                    DDlCompany.DataSource = Worker.GetDataSet(strSQL, conn);
                    DDlCompany.DataTextField = "ABBR";
                    DDlCompany.DataValueField = "ABBR";
                    DDlCompany.DataBind();
                    TextBox TBcompany = (TextBox)e.Row.FindControl("TextBox1");
                    for (int i = 0; i < DDlCompany.Items.Count; i++)
                    {
                        if (TBcompany.Text == DDlCompany.Items[i].Text)
                        {
                            DDlCompany.Items[i].Selected = true;
                        }
                    }
                    //绑定部门
                    string strSQL1 = "select '所有部门' as ABBR  union all select distinct ABBR from [WorkFlow].[dbo].[RUC_Organization](nolock) where OrgTypeID=3 and IfDelete=0 and ABBR !=''";
                    DropDownList DDlDept = (DropDownList)e.Row.FindControl("DropDownList1");
                    DDlDept.DataSource = Worker.GetDataSet(strSQL1, conn);
                    DDlDept.DataTextField = "ABBR";
                    DDlDept.DataValueField = "ABBR";
                    DDlDept.DataBind();
                    TextBox TBDept = (TextBox)e.Row.FindControl("TextBox2");
                    for (int i = 0; i < DDlDept.Items.Count; i++)
                    {
                        if (TBDept.Text == DDlDept.Items[i].Text)
                        {
                            DDlDept.Items[i].Selected = true;
                        }
                    }
                    //绑定类型
                    DropDownList DDlType = (DropDownList)e.Row.FindControl("DropDownList4");
                    string conn1 = WebConfigurationManager.ConnectionStrings["meetingroomManagementConnectionString"].ConnectionString;// "Data Source=mesdbsrv.gwkf.cn;Initial Catalog=VenueBooking;User ID=vbuser;Password=vb_2013";
                    string strSQL2 = "SELECT [Type] FROM [VenueBooking].[dbo].[MTR_bas_Type] where available = 1";
                    DDlType.DataSource = Worker.GetDataSet(strSQL2, conn1); ;
                    DDlType.DataTextField = "Type";
                    DDlType.DataValueField = "Type";
                    DDlType.DataBind();
                    TextBox TBType = (TextBox)e.Row.FindControl("TextBox5");
                    for (int i = 0; i < DDlType.Items.Count; i++)
                    {
                        if (TBType.Text == DDlType.Items[i].Text)
                        {
                            DDlType.Items[i].Selected = true;
                        }
                    }
                    //绑定管理员
                    DropDownList DDLadmin = (DropDownList)e.Row.FindControl("DDLadmin");
                    string strSQL3 = string.Format(@"select distinct [MTR_bas_Admin].[adminName] FROM [VenueBooking].[dbo].[MTR_bas_Admin] where Available = 1 and adminLevel =1 and VenueType = '{0}'", DDlType.SelectedItem.Text);
                    DDLadmin.DataSource = Worker.GetDataSet(strSQL3, conn1);
                    DDLadmin.DataTextField = "adminName";
                    DDLadmin.DataValueField = "adminName";
                    DDLadmin.DataBind();
                    TextBox TBadmin = (TextBox)e.Row.FindControl("TBadmin");
                    for (int i = 0; i < DDLadmin.Items.Count; i++)
                    {
                        if (TBadmin.Text == DDLadmin.Items[i].Text)
                        {
                            DDLadmin.Items[i].Selected = true;
                        }
                    }

                }
                if (uLevel == 2)
                {
                    //绑定公司
                    DropDownList DDlCompany = (DropDownList)e.Row.FindControl("CompanyList");
                    DDlCompany.DataSource = ((DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty)).ToTable(true, "mtrCompanyRuc");
                    DDlCompany.DataTextField = "mtrCompanyRuc";
                    DDlCompany.DataValueField = "mtrCompanyRuc";
                    DDlCompany.DataBind();
                    TextBox TBcompany = (TextBox)e.Row.FindControl("TextBox1");
                    for (int i = 0; i < DDlCompany.Items.Count; i++)
                    {
                        if (TBcompany.Text == DDlCompany.Items[i].Text)
                        {
                            DDlCompany.Items[i].Selected = true;
                        }
                    }
                    //绑定部门
                    DropDownList DDlDept = (DropDownList)e.Row.FindControl("DropDownList1");
                    List<string> dept = new List<string>();
                    dept = getDeptByNameComLevel(Session["userName"].ToString(), TBcompany.Text, uLevel);
                    DDlDept.DataSource = dept;
                    DDlDept.DataBind();

                    TextBox TBDept = (TextBox)e.Row.FindControl("TextBox2");
                    for (int i = 0; i < DDlDept.Items.Count; i++)
                    {
                        if (TBDept.Text == DDlDept.Items[i].Text)
                        {
                            DDlDept.Items[i].Selected = true;
                        }
                    }
                    //绑定类型
                    DropDownList DDlType = (DropDownList)e.Row.FindControl("DropDownList4");
                    string conn = WebConfigurationManager.ConnectionStrings["meetingroomManagementConnectionString"].ConnectionString;
                    string sqlstr = string.Format(@"select distinct [MTR_bas_Admin].VenueType from MTR_bas_Admin with(nolock)
                        where adminName ='{0}'and MTR_bas_Admin.Available='1' and MTR_bas_Admin.adminLevel=2", Session["userName"].ToString());
                    DDlType.DataSource =Worker.GetDataSet(sqlstr, conn);// ((DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty)).ToTable(true, "type");
                    DDlType.DataTextField = "VenueType";
                    DDlType.DataValueField = "VenueType";
                    DDlType.DataBind();
                    TextBox TBType = (TextBox)e.Row.FindControl("TextBox5");
                    for (int i = 0; i < DDlType.Items.Count; i++)
                    {
                        if (TBType.Text == DDlType.Items[i].Text)
                        {
                            DDlType.Items[i].Selected = true;
                        }
                    }
                    //绑定管理员
                    DropDownList DDLadmin = (DropDownList)e.Row.FindControl("DDLadmin");
                    string strSQL3 = string.Format(@"select distinct [MTR_bas_Admin].[adminName] FROM [VenueBooking].[dbo].[MTR_bas_Admin] where Available = 1 and adminLevel =1 and VenueType = '{0}'", DDlType.SelectedItem.Text);
                    DDLadmin.DataSource = Worker.GetDataSet(strSQL3, conn);
                    DDLadmin.DataTextField = "adminName";
                    DDLadmin.DataValueField = "adminName";
                    DDLadmin.DataBind();
                    TextBox TBadmin = (TextBox)e.Row.FindControl("TBadmin");
                    for (int i = 0; i < DDLadmin.Items.Count; i++)
                    {
                        if (TBadmin.Text == DDLadmin.Items[i].Text)
                        {
                            DDLadmin.Items[i].Selected = true;
                        }
                    }
                }
            }
        }

       /// <summary>
       /// 获取部门
       /// </summary>
       /// <param name="userName"></param>
       /// <param name="Company"></param>
       /// <param name="Level"></param>
       /// <returns></returns>
        protected List<string> getDeptByNameComLevel(string userName, string Company, int Level)
        {
            string com = Company;
            List<string> dept = new List<string>();

            string conn = WebConfigurationManager.ConnectionStrings["WorkFlowConnectionString"].ConnectionString;
            string strSQL = string.Format(@"select '所有部门' as ABBR,'0' as ID
                            union all 
                            select ABBR,ID from RUC_Organization(nolock) where IfDelete=0 and ParentID in 
                            (select ID from RUC_Organization(nolock) where IfDelete=0 and ParentID in 
                            (select ID from RUC_Organization(nolock) where ParentID in
                            (select id from RUC_Organization(nolock) where ABBR='{0}' and IfDelete=0) and 
                            IfDelete=0 and OrgTypeID=1)) or ParentID in (select ID from RUC_Organization(nolock)
                             where ParentID in(select id from RUC_Organization(nolock) where ABBR='{0}' and IfDelete=0) and IfDelete=0 and OrgTypeID=2)
                            ", com);
            DataTable dt = Worker.GetDataSet(strSQL, conn).Tables[0];
            dept = dt.AsEnumerable().Select(p => p[0].ToString().ToLower()).ToList();
            return dept;
        }
        /// <summary>
        /// 选择公司后绑定部门数据源
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void mtrCompanyRuc_SelectedIndexChanged(object sender, EventArgs e)
        {
            string com = mtrCompanyRuc.SelectedItem.Text;
            List<string> dept = new List<string>();
            dept = getDeptByNameComLevel(Session["userName"].ToString(), com, uLevel);
            List_dept.DataSource = dept;
            List_dept.DataBind();
        }

        protected void types_SelectedIndexChanged(object sender, EventArgs e)
        {
            string conn = WebConfigurationManager.ConnectionStrings["meetingroomManagementConnectionString"].ConnectionString;
            string strSQL = string.Format(@"select distinct [MTR_bas_Admin].[adminName] FROM [VenueBooking].[dbo].[MTR_bas_Admin] where Available = 1 and adminLevel =1 and VenueType = '{0}'", types.SelectedItem.Text);
            admin.DataSource = Worker.GetDataSet(strSQL, conn);
            admin.DataTextField = "adminName";
            admin.DataValueField = "adminName";
            admin.DataBind();
            if (types.SelectedItem.Text=="会议室")
            {
                mtrLongestBookingDay.Text = "4";
                mtrLongestAdvanceBookingTime.Text = "15";
            }

        }
        /// <summary>
        /// 判断字符串是否为空
        /// </summary>
        /// <param name="check"></param>
        public bool isnull(string check) {
            if (string.IsNullOrWhiteSpace(check))
            {
                return false;
            }
            else
                return true;
        }
        /// <summary>
        /// 添加记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                string venueName = mtrName.Text;
                if (string.IsNullOrWhiteSpace(venueName))
                {
                    Label10.Text ="<script>alert('请输入场地名称！'); </script>";
                    mtrName.Focus();
                    return;
                }
                string com = mtrCompanyRuc.SelectedItem.Text;
                //string dept = mtrDeptRuc.SelectedItem.Text;
                if (string.IsNullOrWhiteSpace(com))
                {
                    Label10.Text ="<script>alert('请选择场地来源！'); </script>";
                    mtrCompanyRuc.Focus();
                    return;
                }
                string adminName = admin.SelectedItem.Text;
                
                string venueType = types.SelectedItem.Text;
                string Address = mtrAddress.SelectedItem.Text;
                string Address1 = mtrAddress1.Text;
                if (string.IsNullOrWhiteSpace(Address1))
                {
                    Label10.Text ="<script>alert('请输入地址'); </script>";
                    mtrAddress1.Focus();
                    return;
                }
                if (string.IsNullOrWhiteSpace(mtrCap.Text))
                {
                    Label10.Text ="<script>alert('请输入容量'); </script>";
                    mtrCap.Focus();
                    return;
                }
                int cap = Convert.ToInt32(mtrCap.Text);
                string phone = mtrPhone.Text;
                string isvip = mtrType.SelectedItem.Text;

                if (string.IsNullOrWhiteSpace(mtrLongestBookingDay.Text))
                {
                    Label10.Text ="<script>alert('请输入最长预定时常'); </script>";
                    mtrLongestBookingDay.Focus();
                    return;
                }
                if (string.IsNullOrWhiteSpace(mtrLongestAdvanceBookingTime.Text))
                {
                    Label10.Text ="<script>alert('请输入预定最长提前天数'); </script>";
                    mtrLongestAdvanceBookingTime.Focus();
                    return;
                }
                int mlbd = Convert.ToInt32(mtrLongestBookingDay.Text);
                int mlabt = Convert.ToInt32(mtrLongestAdvanceBookingTime.Text);
                //
                int k = 0;
                //所有部门被选中
                if (List_dept.Items[0].Selected)
                {
                    AddVenueByDept(venueName, venueType, com, "所有部门", Address, Address1, cap, phone, isvip, mlbd, mlabt, adminName);
                    k++;
                }
                //所有部门未被选中
                else if (!List_dept.Items[0].Selected)
                {
                    for (int i = 0; i < List_dept.Items.Count; i++)
                    {
                        if (List_dept.Items[i].Selected == true)
                        {
                            //存入一行到数据库
                            string dept = List_dept.Items[i].Value;
                            AddVenueByDept(venueName, venueType, com, dept, Address, Address1, cap, phone, isvip, mlbd, mlabt,adminName);
                            k++;
                        }
                    }
                }
                if (k==0)
                {
                    Label10.Text = "<script>alert('请选择场地来源！'); </script>";
                    return;
                }
                Label10.Text ="<script>alert('新场地添加成功！'); </script>";
                Response.Redirect("MeetingroomManage.aspx", false);
            }
            catch (Exception ex)
            {
                Worker w = new Worker();
                w.writeErrorMessage("0", ex, "添加场地");

               Label10.Text ="<script>alert('" + ex.Message + "'); </script>";
            }
        }

        protected void AddVenueByDept(string venueName, string venueType, string com, string dept, string Address, string Address1,
            int cap, string phone, string isvip, int mlbd, int mlabt,string adminName)
        {
            try
            {
                using (meetingroomManagementEntities useAdd = new meetingroomManagementEntities())
                {
                    //场地实体
                    MTR_bas_Meetingroom mbm = new MTR_bas_Meetingroom();
                    mbm.mtrName = venueName;
                    mbm.type = venueType;
                    mbm.mtrCompanyRuc = com;
                    mbm.mtrDeptRuc = dept;
                    mbm.mtrAddress = Address;
                    mbm.mtrAddress1 = Address1;
                    mbm.mtrCapacity = cap;
                    mbm.mtrPhone = phone;
                    mbm.mtrType = isvip;
                    mbm.mtrFreeTime = "8:00-17:00";
                    mbm.mtrState = true;
                    mbm.mtrLongestBookingDay = mlbd;
                    mbm.mtrLongestAdvanceBookingTime = mlabt;
                    mbm.mtrDelete = true;
                    mbm.undefine3 = adminName;

                    useAdd.MTR_bas_Meetingroom.Add(mbm);
                    //写入数据库，完成增加操作
                    useAdd.SaveChanges();
                }
            }
            catch(Exception ee){
                throw ee.InnerException;
            }
        }

        protected void reset_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 获取场地类型
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void mtrDeptRuc_SelectedIndexChanged()
        {
            List<string> vunueType = new List<string>();
            vunueType = getVenueTypeByNameComLevelDept(Session["userName"].ToString(), mtrCompanyRuc.SelectedItem.Text, uLevel);
            types.DataSource = vunueType;
            types.DataBind();
        }


        protected List<string> getVenueTypeByNameComLevelDept(string Name, string com, int level)
        {
            List<string> type = new List<string>();
            type.Clear();
            if (level == 2)
            {
                foreach (MTR_Admin ma in AdminInfoList)
                {
                    type.Add(ma.VenueType);
                }
                type.Insert(0, "");
            }
            if (level == 3)
            {
                using (var mtr_resEn = new meetingroomManagementEntities())
                {
                    var cls = (from c in mtr_resEn.MTR_bas_Type
                               where c.available
                               select c.Type).Distinct();
                    foreach (var c in cls)
                    {
                        type.Add(c.ToString());
                    }
                    type.Insert(0, "");
                }
            }
            return type;
        }

        protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList venueType = sender as DropDownList;
            GridViewRow gvr = (GridViewRow)venueType.NamingContainer;
            TextBox type = gvr.FindControl("TextBox5") as TextBox;
            type.Text = venueType.SelectedItem.Text;

            DropDownList admin = gvr.FindControl("DDLadmin") as DropDownList;
            TextBox TBadmin = gvr.FindControl("TBadmin") as TextBox;
            string conn = WebConfigurationManager.ConnectionStrings["meetingroomManagementConnectionString"].ConnectionString;
            string strSQL = string.Format(@"select distinct [MTR_bas_Admin].[adminName] FROM [VenueBooking].[dbo].[MTR_bas_Admin] where Available = 1 and adminLevel =1 and VenueType = '{0}'", venueType.SelectedItem.Text);
            admin.DataSource = Worker.GetDataSet(strSQL, conn);
            admin.DataTextField = "adminName";
            admin.DataValueField = "adminName";
            admin.DataBind();

            if (admin.Items.Count < 1) {
                admin.Items.Insert(0, "");
            }

            for (int i = 0; i < admin.Items.Count; i++)
            {
                if (TBadmin.Text == admin.Items[i].Text)
                {
                    admin.Items[i].Selected = true;
                }
            }
        }


        protected void List_dept_SelectedIndexChanged(object sender, EventArgs e)
        {
            //所有部门被选中
            //if (List_dept.Items[0].Selected) 
            //{
            //    for (int i = 0; i < List_dept.Items.Count; i++) {
            //        List_dept.Items[i].Selected = true;
            //    }
            //}
        }

        protected void GridView1_DataBound(object sender, EventArgs e)
        {

        }

        protected void DDLadmin_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList DDLadmin = sender as DropDownList;
            GridViewRow gvr = (GridViewRow)DDLadmin.NamingContainer;
            TextBox type = gvr.FindControl("TBadmin") as TextBox;
            type.Text = DDLadmin.SelectedItem.Text;
        }
    }
}